package com.imooc.concurrent.threadAndRunnable;

/**
 * Thread不能被多个线程共享，并且不容易扩展
 */
public class ThreadDemo {

    public static void main(String[] args) {
        MyThread myThread1 = new MyThread("窗口1");
        MyThread myThread2 = new MyThread("窗口2");
        MyThread myThread3 = new MyThread("窗口3");

        myThread1.start();
        myThread2.start();
        myThread3.start();
    }
}

class MyThread extends Thread{
    private int ticketsCont = 5;//一共有5张火车票
    private String name;//窗口

    public MyThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        while (ticketsCont>0){
            ticketsCont--;
            System.out.println(name+"卖了一张票，剩余票数为:"+ticketsCont);
        }
        System.out.println("");
    }
}


